package com.cysyz.mylib.datacopytool.getterandsetteradapter;

import com.cysyz.mylib.datacopytool.GetterAndSetterType;

import java.util.List;


public class ListGetterAndSetterAdapter implements GetterAndSetterAdapter{

	@Override
	public boolean supports(Object obj) {
		if (obj instanceof List) {
			return true;
		}
		return false;
	}

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public void setValue(Object obj, String valueId, Object val) {
        ((List)obj).add(val);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public String[] getAllValueIds(Object obj) {
        int size = ((List)obj).size();
        String[] result = new String[size];
        for (int i = 0 ; i < size ; i ++) {
            result[i] = i + "";
        }
        return result;
    }



    @SuppressWarnings("rawtypes")
    @Override
    public Object getValue(Object obj, String valueId) {
        return ((List)obj).get(Integer.parseInt(valueId));
    }



    @Override
    public GetterAndSetterType getGetterAndSetterType() {
        return GetterAndSetterType.INDEX;
    }

}
